# ====================================
# Company: Zonge International, INC.
# Developer: Wanjie Feng
# Date: 10/13/2023
# Time: 1:04 PM
# Filename: Read_cvs.py
# IDE: PyCharm
# =====================================

import pandas as pd

def Read_cvs(fileloc):
    '''This routine reads the data inside cvs files.
       The CVS file contains column name and data.
    '''
    try:
        #read in data as data frame
        data = pd.read_csv(fileloc)

        #change freq from 1khz to 1000
        SR = []
        for I in range(len(data['freq'])):
            temp = data['freq'][I]
            if 'hz' in temp:
                temp = temp[0:-2]
                if 'k' in temp:
                    temp = int(temp[0:-1])*1000
                else:
                    temp = int(temp)
            SR.append(temp)
        data['freq'] = SR

        #rename the column name
        data.rename(columns={'freq': 'Sampling Rate', 'loop_indx': 'Cycle', 'sample_indx': 'Data Point'}, inplace=True)

        #change TX_V to V
        data['TX_V'] = data['TX_V'] * 100
        return data
    except Exception as e:
        print('Read txt', e)